<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${pageContext.request.contextPath }/static/layui/css/layui.css">
<script src="${pageContext.request.contextPath }/static/js/jquery-1.12.4.min.js"></script>
<script src="${pageContext.request.contextPath }/static/layui/layui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/dataTable.js"></script>
</head>
<body style="background: #ffffff">
	
	<input type="hidden"  id="uuid" value="${uuid}">
	
	<table class="layui-hide" id="systemdata" lay-filter="systemdata"></table>
	
	<script type="text/html" id="toolbarDemo">
		<div class="layui-btn-container">
			<button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
			<button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
  		</div>
	</script>
	<script type="text/javascript">
		layui.use("table", function(){
			var table = layui.table;
			var uuid = $("#uuid").val();
			table.render({
				elem:'#systemdata',
				title:'数据字典',
				url: '${pageContext.request.contextPath }/dict/systemdata/page?systemDictionaries='+uuid,
				toolbar: '#toolbarDemo',
				page: true,
				cols: [[
					{type: 'radio', fixed: 'left'},
					{field: 'id', title: 'ID', hide: true, usersize: true, sort: true},
					{field: 'name', title: '字典数据'},
					{field: 'code', title: '数据代码'}
				]] 
			});
			table.on('toolbar(systemdata)', function(obj){
				var checkStatus = table.checkStatus('systemdata');
				var data = checkStatus.data;
				if(obj.event === "add"){
					$.post("${pageContext.request.contextPath }/dict/systemdata/edit", {uuid: uuid}, function(data){
						layui.use('layer', function(){
	      					layer.open({
	      						title: '新增',
	      						shadeClose: true,
	    	      				shade: false,
	    	      				maxmin: true,
	    			            area: ['400px', '240px'],
	    			            content: data,
	    			            btn: ['确定', '取消'],
	    			            yes:function(){
	    			            	var name = $("#data_name").val();
									var code = $("#data_code").val();
									$.post("${pageContext.request.contextPath }/dict/systemdata/save",{
										name: name,
										code: code,
										systemDictionaries:uuid
									},function(result){
		    			            	table.reload('systemdata', {
										  	url: '${pageContext.request.contextPath }/dict/systemdata/page?systemDictionaries='+uuid
										});
		    			            	$("#systemData")[0].reset();
				      					layer.close(layer.index);
									});
			      				},
			      				btn2:function(){
			      					$("#systemData")[0].reset();
			      					layer.close(layer.index);
			      				}
	      					});
						});						
					});
				}else if(obj.event === "delete"){
					if(data.length != 1){
						layer.msg('请选中一行进行删除');	
					}else{
						layer.confirm('确定要删除吗？', function(index) {
				        	var id = data[0].id;
				        	$.post("${pageContext.request.contextPath }/dict/systemdata/delete", {id: id}, function(result){
				        		table.reload('systemdata', {
								  	url: '${pageContext.request.contextPath }/dict/systemdata/page?systemDictionaries='+uuid
								});
				        	});
				        	layer.close(index);
			        	});
					}
				}
			});
		});
	</script>
</body>
</html>